package com.chinafree.chat.controller;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

import org.apache.catalina.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/** 
 * @Class: Test
 * @Description: 简单websocket demo
 * @author 九风萍舟
 */
/**
 * TODO websocket服务
 *
 * @author xiaoshuaishuai
 * @date 2019-05-21 11:19
 */
@Slf4j
@ServerEndpoint(value = "/websocket")
@Component
public class WebSocketController {

    /**
     * 当前连接数量
     */
    private static volatile int onlineCount = 0;

    private static ConcurrentHashMap<Session, User> loginMap = new ConcurrentHashMap<>();

    @OnOpen
    public void onOpen(Session session) {
        System.out.println("I'm Coming......");
    }

    @OnClose
    public void onClose() {
        log.info("close");
    }

    @OnError
    public void onError(Session session, Throwable error) {
        System.out.println("Error");
    }

    @OnMessage
    public void onMessage(String message, Session session) {
        log.info(message);
    }

}